﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using PersistenceCommons;


using NHibernate;
using NHibernate.Cfg;
using NHibernate.Criterion;

namespace DGMTCC_ASM2009
{
    /// <summary>
    /// Interaction logic for ObjectAnalised.xaml
    /// </summary>
    public partial class ObjectAnalised : Window
    {
        IList<AnalysisObject> analysisObjects;

        public ObjectAnalised(IList<AnalysisObject> analysisObjectsReturned)
        {
            analysisObjects = analysisObjectsReturned;

            
            InitializeComponent();
        }

       

       

        private void ObjectAnalyzed_Loaded(object sender, RoutedEventArgs e)
        {


            if (analysisObjects.Count > 1)
            {
                foreach (AnalysisObject anb in analysisObjects)
                {
                    txtResults.Visibility = Visibility.Visible;


                    txtResults.Text += "Resultados:\n\n";

                    txtResults.Text += anb.analysisObjectPID + "\n";
                    txtResults.Text += anb.analysisObjectPackagePID + "\n";
                    txtResults.Text += "Data Fabricação" + anb.factoryDate.ToString() + "\n";
                    txtResults.Text += "Data Análise" + anb.analysisDate.ToString() + "\n";

                    foreach (AnalysisObjectComponent aoc in anb.analysisObjectComponent)
                    {
                        txtResults.Text += aoc.analysisObjectComponentPID.ToString() + "\n";
                        txtResults.Text += aoc.analysisQualityResultP1.ToString() + "\n";
                        txtResults.Text += aoc.analysisQualityResultP2.ToString() + "\n\n";

                    }

                }
            }

            if (analysisObjects.Count == 1)
            {

                Polyline mPolyline = new Polyline();
                mPolyline.Stroke = System.Windows.Media.Brushes.Red;
                mPolyline.StrokeThickness = 2;
                mPolyline.FillRule = FillRule.EvenOdd; 
                PointCollection Points = new PointCollection();
                int pointsCount = 0;
                
                    foreach (AnalysisObjectComponent an in analysisObjects.First().analysisObjectComponent)
                    {
                        pointsCount++;
                        double y1 = an.analysisQualityResultP1 / 10;
                        double x1 = pointsCount*10;
                        Point p1 = new Point(x1, y1);
                        
                        pointsCount++;

                        double y2 = an.analysisQualityResultP2 / 10;
                        double x2 = pointsCount * 10;
                        Point p2 = new Point(x2, y2);

                        Points.Add(p1);
                        Points.Add(p2);
                    }
              
             
                mPolyline.Points = Points;
                myGrid.Children.Add(mPolyline);


            }
        }
       
    }
}


//Configuration configuration = new NHibernate.Cfg.Configuration().Configure();
//ISessionFactory factory = configuration.BuildSessionFactory();



//using (ISession session = factory.OpenSession())
//{

//    ICriteria criteria = session.CreateCriteria<LoginUser>();
//    var login = criteria.
//        Add(NHibernate.Criterion.Expression.Eq("loginUserID", "EGC2009")).
//        Add(NHibernate.Criterion.Expression.Eq("loginUserPIN", "Raptrap22")).
//        List<LoginUser>();

//}



//Configuration configuration = new NHibernate.Cfg.Configuration().Configure();
//ISessionFactory factory = configuration.BuildSessionFactory();

//new NHibernate.Tool.hbm2ddl.SchemaExport(configuration).Create(true, true);

//using (ISession session = factory.OpenSession())
//using (ITransaction t = session.BeginTransaction())
//{
//    LoginUser instanceLoginUser = new LoginUser();
//    AnalysisObjectComponent anc = new AnalysisObjectComponent();
//    AnalysisObjectComponent anc1 = new AnalysisObjectComponent();
//    AnalysisObject an = new AnalysisObject();


//    instanceLoginUser.loginUserID = "EGC2009";
//    instanceLoginUser.loginUserName = "Guilherme";
//    instanceLoginUser.loginUserLastName = "Moreira";
//    instanceLoginUser.loginUserPIN = "Raptrap22";
//    session.Save(instanceLoginUser);


//    an.analysisDate = DateTime.Now;
//    an.analysisObjectPackagePID = "codAmostraPadrão";
//    an.analysisObjectPID = "codAmostra001";
//    an.analysisUser = instanceLoginUser;
//    an.factoryDate = DateTime.Now;

//    anc.analysisObject = an;
//    anc1.analysisObject = an;

//    anc.analysisObjectComponentPID = "C0";
//    anc.analysisQualityResultP1 = 1743;
//    anc.analysisQualityResultP2 = 1743;

//    anc1.analysisObjectComponentPID = "C0";
//    anc1.analysisQualityResultP1 = 1744;
//    anc1.analysisQualityResultP2 = 1744;

//    session.Save(an);

//    //session.Save(anc);

//    //session.Save(anc1);

//    t.Commit();
//}